package com.webdesign.dao.jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;


public class TbHomeworkSQL {
	
	/*
	 * clover 取得tbhomework表格的homeworkid的最大值，返回类型为String
	 */
	public String getMaxHomeworkid(){
		Connection conn = null;
		Statement stmt = null;
		ResultSet rs = null;
		String strs = null;
		Integer maxHomeworkId = 0;
		String [] sHomeworkId = null;
		try {
			conn = DBConnection.getConnection();
			stmt = conn.createStatement();
			rs = stmt.executeQuery("select HomeworkID as HomeworkID from tb_homework");
			while (rs.next()) {
				strs=rs.getString("HomeworkID");
				sHomeworkId = strs.split("_");
				if(Integer.parseInt(sHomeworkId[1]) > maxHomeworkId){
					maxHomeworkId = Integer.parseInt(sHomeworkId[1]);
				}
			}
		} catch (SQLException e) {
			e.printStackTrace();
		}
		return "1_" + maxHomeworkId;
	}
}
